package com.goldgov.SmsSend.service.impl;

import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.goldgov.SmsSend.service.IMasSendSmsService;
import com.mascloud.sdkclient.Client;
@Service
public class MasSendSmsServiceImpl implements IMasSendSmsService{
	protected final Logger logger = Logger.getLogger(getClass());
	
	@Override
	public boolean sendSms(String phonenumber, String sendMessage) {
		
					/*// 1：应用AppKey
					String appkey = (String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"plugins_sms_aliyunSms_appkeyid");
					
					// 2:应用秘钥
					String secret = (String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"plugins_sms_aliyunSms_appsecret");
					// 3：签名信息
					String signName = (String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"plugins_sms_signName");
					Integer timeOutInt = Integer.valueOf((String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"plugins_sms_captcha_PeriodOfValidity"));
					//企业名称
					String productName = (String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"product_name");
					//接口名称
					String smsUrl = (String) ConfigHolder.getConfigValue("org.gtiles.components.sms.send.service.impl",
							"plugins_sms_alibabaSms_url");
					*/
					String smsUrl="http://112.35.4.197:15000";
					String appkey="zzqzzb";
					String secret="passwd@5098";
					String productName="政企分公司测试";
					String signName="DWItALe3A";
					Integer timeOutInt=5;
					
					//设置超时时间-可自行调整
					System.setProperty("sun.net.client.defaultConnectTimeout", null == timeOutInt ? "10000":(timeOutInt*60000+""));
					System.setProperty("sun.net.client.defaultReadTimeout", null == timeOutInt ? "10000":(timeOutInt*60000+""));
					
					Client client = Client.getInstance( );
					boolean isLoggedin = client.login( smsUrl, appkey, secret, productName );
					if( isLoggedin ) {
						String[] mobiles = phonenumber.split(",");
						//手机号，短信内容，扩展码（需申请通道，没有填默认的），优先级（1-5）1最低，网关签名，唯一标识，是否上行，ture为是
						int sendResult = client.sendDSMS( mobiles, sendMessage, "123", 1,signName, UUID.randomUUID().toString(), false );
						if( sendResult == mobiles.length ) {
							return true;
						} else {
							logger.error("Send SMS Error Message:Failed to send " + mobiles.length + " SMS(s)");
						}
					} else {
						logger.error("Send SMS Error Message:Login failed");
					}
		return false;
	}
}
